$(function() {
	doSearch();
});

function doSearch() {
	var mark = $('#mark').val();
	var startTime = $('#startTime').datetimebox('getValue');
	var endTime = $('#endTime').datetimebox('getValue');
	var type = $('#type').combobox('getValue');
	
	if (startTime != "" && endTime != "") {
		var sDay = startTime.substring(0,10);
		var eDay = endTime.substring(0,10);
		
		var sDate = new Date(sDay);      
	    var eDate = new Date(eDay);  
	    
	    if (sDate.getTime()-eDate.getTime() != 0) {
	    	alert("请选择同一天！");
	    	return false;
	    }
		
		var diff = GetDateDiff(startTime, endTime, "second");
		if (diff > 0) {
			alert("开始时间不能小于结束时间！");
			return false;
		}
	}
	
	var xAxis = [];
	var yAxis = [];
	var avg;
	$.ajax({
		url : '/flow/bigFlowData',
		data : {
			mark : mark,
			startTime : startTime,
			endTime : endTime,
			type : type
		},
		type : "POST",
		datatype : "json",
		async : true,
		success : function(data) {
			xAxis = data.xAxis;
			yAxis = data.yAxis;
			flowHandler.showHighChart(xAxis, yAxis);
		}
	});
}

function GetDateDiff(startTime, endTime, diffType) {
    //将计算间隔类性字符转换为小写
    diffType = diffType.toLowerCase();
    var sTime = new Date(startTime);      //开始时间
    var eTime = new Date(endTime);  //结束时间
    
    var divNum = 1;
    switch (diffType) {
        case "second":
            divNum = 1000;
            break;
        case "minute":
            divNum = 1000 * 60;
            break;
        case "hour":
            divNum = 1000 * 3600;
            break;
        case "day":
            divNum = 1000 * 3600 * 24;
            break;
        default:
            break;
    }
    return parseInt((sTime.getTime() - eTime.getTime()) / parseInt(divNum));
}
